<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>安全警示类型管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/frontEnd/images/favicon.ico">
    <link rel="stylesheet" href="/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuicms/css/public.css" media="all" />
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/layuicms/js/x-layui.js"></script>
    <script>

    </script>
</head>

<body class="childrenBody">
    <!-- 查询条件开始 -->
<!--    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend>查询条件</legend>
    </fieldset>-->
    <blockquote class="layui-elem-quote" style="height: 50px;">
        <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">警示类型</label>
                    <div class="layui-input-inline">
                        <select name="safetyId" class="search_safety">
                            <option value="0">请选择安全警示类型</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">文件类型</label>
                    <div class="layui-input-inline">
                        <select name="fileType">
                            <option value="0">文件类型</option>
                            <option value="1">PPT</option>
                            <option value="2">视频</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">案例标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="classicTitle" placeholder="请输入典型案例标题"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block" style="text-align: center;">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"> <span class="layui-icon layui-icon-search"></span> 查询</button>
                        <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span> 重置</button>
                    </div>
                </div>
            </div>
        </form>
    </blockquote>
    <!--查询条件结束-->
    <!--数据表格开始-->
    <div>

        <table class="layui-hide" id="caseClassicManagementTable" lay-filter="caseClassicManagementTable"></table>
        <div id="caseClassicManagementToolBar" style="display: none ;"  >
            <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-circle"></span> 添加典型案例</button>
        </div>
        <div id="caseClassicManagementRowBar" style="display: none">
            <input type="hidden" id="editId">
            <button type="button" lay-event="update" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-edit"></span> 修改</button>
            <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span> 删除</button>
        </div>
    </div>
    <!--数据表格结束-->

</body>
<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer',],function(){
        var $ = layui.jquery;
        var form=layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var tableIns = table.render({
             elem: '#caseClassicManagementTable'
            ,url:'/caseClassic/loadAllCaseClassic'
            ,toolbar: '#caseClassicManagementToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                 title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '典型案例数据表'
             ,height:'full-140'
             ,page: true
            ,cols: [ [
                 {field:'',title:'序号', type:'numbers', width: 80, align: 'center', unresize: true, sort: true}
                ,{field:'safetyName', title:'安全警示类型',align: 'center'}
                ,{field:'coreType', title:'所属文件夹',align: 'center'}
                ,{field:'fileType', title:'文件类型' , align: 'center',templet:function(d){
                            return d.fileType==1?'<font color="green">PPT案例</font>':'<font color="#F75000">视频案例</font>';
                }}
                ,{field:'classicTitle', title:'案例标题',width:200}
                ,{field:'createDate', title:'创建日期',width:160}
                ,{field:'available', title:'是否可用',width:80,templet:function(d){
                        return d.available==1?'<font color=blue>可用</font>':'<font color=red>不可用</font>';
                    }}
                ,{field:'ordernum', title:'排序码',width:80}
                ,{fixed: 'right', title:'操作', toolbar: '#caseClassicManagementRowBar' ,align: 'center',width:220}
            ] ]
        });
         //模糊查询
        form.on("submit(doSearch)",function (data) {
           tableIns.reload({
               where:data.field,
               page:{
                   curr:1
               }
           });
            return false;
        });
        //加载查询条件供应商的下拉列表
        $.get("/safetyAlertType/loadAllsafetyAlertTypeForSelect",function(res){
            var data=res.data;
            var dom=$(".search_safety");
            var html='<option value="0">请选择警示类型</option>'
            $.each(data,function(index,item){
                html+='<option value="'+item.id+'">'+item.typename+'</option>'
            });
            dom.html(html);
            form.render("select");
        });
        //监听工具条事件
        table.on('toolbar(caseClassicManagementTable)', function(obj){
            switch(obj.event){
                case 'batchDelete':
                    batchDelete();
                    break;
                case 'add':
                    admin_tiaozheng('添加典型案例', '/safety/toAddClassicManager', '700', '500');
                    break;
            };
        });
        //监听行工具条事件
        table.on('tool(caseClassicManagementTable)', function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'update':
                    //toEditCaseClassicManager
                    admin_edit('修改案例汇编', '/safety/toEditClassicManager', data,'700', '500')
                    break;
                case 'delete':
                    deleteCaseClassicManagement(data);
                    break;
            };
        });
        var mainIndex;
        var url;
        function admin_edit(title, url,data, w, h) {
            var dataId = data.id
            $("#editId").val(dataId);
            x_my_show(title, url, w, h);
        }
        function admin_tiaozheng(title, url, w, h) {
            x_my_show(title, url, w, h);
        }
        //添加和修改的提交
        form.on("submit(doSubmit)",function (data) {
            $.post(url,data.field,function (res) {
                if(res.code==20000){
                    tableIns.reload();
                }
                layer.msg(res.message);
                layer.close(mainIndex);
            })
            return false
        });

        //根据ID删除
        function deleteCaseClassicManagement(data) {
            layer.confirm('你确定删除【'+data.classicTitle+'】吗?', {icon: 3, title:'提示'}, function(index){
            $.post("/caseClassic/deleteCaseClassic",{id:data.id},function (res) {
                        if(res.code==20000){
                            tableIns.reload();
                        }
                        layer.close(res.message);
                    })
                    layer.close(index);
                }
            )};
    });
</script>
</html>